<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="include/common-header :: common_header(~{::title},~{::link})">
    <title>经费审核</title>
</head>
<body class="gray-bg">

<!--页面内容开始-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>待审核经费</h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <div class="m-l-xs toolbar" id="moneyinfodetailAudit_table_toolbar">
                            <form role="form" id="moneyinfodetailAudit_query_form" class="form-inline">
                                <div class="form-group m-r-xs">
                                    <label for="moneyinfodetailAudit_moneyTypeCode" class="sr-only">经费类型</label>
                                    <select class="form-control" id="moneyinfodetailAudit_moneyTypeCode"
                                            name="moneyTypeCode">
                                        <option value="">-- 请选择 --</option>
                                        <option value="001">直接支付</option>
                                        <option value="002">授权支付</option>
                                        <option value="003">自有资金</option>
                                    </select>
                                </div>
                                <div class="form-group m-r-xs">
                                    <label for="moneyinfodetailAudit_key" class="sr-only">预算项目</label>
                                    <input type="text" class="form-control" id="moneyinfodetailAudit_key"
                                           name="key" placeholder="预算项目/经济分类">
                                </div>
                                <div>
                                    <button class="btn btn-primary" type="button"
                                            onclick="moneyinfodetailAuditObj.refreshTable()">查询
                                    </button>
                                    <button class="btn btn-white" type="button"
                                            onclick="moneyinfodetailAuditObj.resetTable()">重置
                                    </button>
                                    <button class="btn btn-success" type="button"
                                            onclick="moneyinfodetailAuditObj.auditAgreeHandle()">通过
                                    </button>
                                    <button class="btn btn-danger" type="button"
                                            onclick="moneyinfodetailAuditObj.auditNotAgreeHandle()">不通过
                                    </button>
                                </div>
                            </form>
                        </div>
                        <table id="moneyinfodetailAudit_table" class="table table-striped"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--页面内容结束-->
<div th:replace="include/common-js :: common_js"></div>
<script type="text/javascript">
    $(function () {
        moneyinfodetailAuditObj.myTable = $('#moneyinfodetailAudit_table').bootstrapTable({
            toolbar: '#moneyinfodetailAudit_table_toolbar',
            pagination: true,
            sidePagination: 'server',
            method: 'post',
            clickToSelect: true,
            queryParams: function (param) {
                param.moneyTypeCode = $("#moneyinfodetailAudit_moneyTypeCode").val();
                param.key = $('#moneyinfodetailAudit_key').val();
                param.queryState = 0;
                return param;
            },
            url: "/money/cur/moneyinfodetail",
            formatNoMatches: function () {  //没有匹配的结果
                return '暂无数据';
            },
            columns: [{
                title: '#',
                align: 'center',
                checkbox: true,
                width: 50,
                formatter: function (value, row, index) {
                    return index + 1;
                }
            }, {
                title: '经费类型',
                field: 'moneyTypeName'
            }, {
                title: '预算项目',
                field: 'projectName',
                formatter: function (value, row, index) {
                    return value + `(${row.projectCode})`;
                }
            }, {
                title: '经济分类',
                field: 'cateName',
                formatter: function (value, row, index) {
                    return value + `(${row.cateCode})`;
                }
            }, {
                title: '金额',
                field: 'money',
                formatter: function (value, row, index) {
                    return $.moneyFormat(value);
                }
            }, {
                title: '创建时间',
                field: 'createTime'
            }],
            responseHandler: function (res) {
                return {
                    total: res.page.totalCount,
                    rows: res.page.list
                };
            },
            onLoadSuccess: function (data) {
                $('[data-toggle="tooltip"]').tooltip()
            }
        });
    })
    var moneyinfodetailAuditObj = new Object({
        myTable: undefined,
        queryForm: {
            deptCode: undefined,
            projectName: undefined,
            cateName: undefined
        },
        refreshTable: function () {
            this.myTable.bootstrapTable('refresh')
        },
        resetTable: function () {
            $('#moneyinfodetailAudit_query_form')[0].reset();
            this.refreshTable();
        },
        auditAgreeHandle: function (id) {
            let _self = this;
            let ids = id ? [id] : _self.myTable.bootstrapTable('getSelections').map(o=>{return o.id;});
            if(ids.length == 0){
                toastr.error("请选择要审核的记录", '操作失败')
                return false;
            }
            $.mySwalConfirm("将通过选择的经费，确认吗？", function () {
                $.myPut({
                    url: `/money/cur/moneyinfodetail/audit/agree`,
                    dataType: 'json',
                    data: ids,
                    success: function (data) {
                        if (data && data.code === 0) {
                            toastr.success(data.msg, '操作提示')
                            _self.refreshTable();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            });
        },
        auditNotAgreeHandle: function (id) {
            let _self = this;
            let ids = id ? [id] : _self.myTable.bootstrapTable('getSelections').map(o=>{return o.id;});
            if(ids.length == 0){
                toastr.error("请选择要审核的记录", '操作失败')
                return false;
            }
            $.mySwalConfirm("将不通过选择的经费，确认吗？", function () {
                $.myPut({
                    url: `/money/cur/moneyinfodetail/audit/notagree`,
                    dataType: 'json',
                    data: ids,
                    success: function (data) {
                        if (data && data.code === 0) {
                            toastr.success(data.msg, '操作提示')
                            _self.refreshTable();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            });
        }
    })
</script>
</body>
</html>